class Solution
{
public:
    vector<int> getSubarrayBeauty(vector<int> &nums, int k, int x)
    {
        map<int, int> numCount;
        for (int i = 0; i < k; ++i)
        {
            ++numCount[nums[i]];
        }
        auto queryX = [&]()
        {
            int accumulateCount = 0;
            for (auto [num, count] : numCount)
            {
                if (num >= 0)
                {
                    return 0;
                }
                accumulateCount += count;
                if (accumulateCount >= x)
                {
                    return num;
                }
            }
            return 0;
        };

        vector<int> result{queryX()};
        for (int i = k; i < nums.size(); ++i)
        {
            --numCount[nums[i - k]];
            ++numCount[nums[i]];
            result.push_back(queryX());
        }
        return result;
    }
};